//package com.kehutong.wwin.service.service;
//
//import static com.kehutong.wwin.service.service.CorpService.valid;
//
//import java.time.LocalDateTime;
//
//import org.coraframework.inject.Inject;
//import org.coraframework.json.JSONObject;
//import org.coraframework.logger.Logger;
//import org.coraframework.logger.LoggerFactory;
//import org.coraframework.mvc.webservice.WebService;
//import org.coraframework.orm.jdbc.JdbcSession;
//
//import com.kehutong.common.urlconfig.WorkerUrlConfig;
//import com.kehutong.wwin.service.entity.Corp;
//import com.kehutong.wwin.service.entity.Suite;
//
//@WebService("/kht-bin/wwin/suite")
//public class SuiteSettingService {
//
//	protected static final Logger logger = LoggerFactory.getLogger(SuiteSettingService.class);
//	@Inject
//	private WorkerUrlConfig workerConfig;
//	@Inject
//	private JdbcSession jdbcSession;
//	@Inject
//	private CorpService corpService;
//
//	/**
//	 * 获取应用Access_token
//	 * @param suite
//	 * @return
//	 * @throws Exception
//	 */
//	public String getSuiteAccessToken(Suite suite) throws Exception {
//		if (valid(suite.getAccessTokenExpiredTime())) {
//			return suite.getAccessToken();
//		}
//
//		JSONObject jsonObject = workerConfig.get("/cgi-bin/gettoken", http -> {
//			Corp enterprise = corpService.getCorpById(suite.getCorpId());
//            http.addParam("corpid", enterprise.getId());
//            http.addParam("corpsecret", suite.getSecret());
//        });
//		
//		suite.setAccessToken(jsonObject.getString("access_token"));
//		suite.setAccessTokenExpiredTime(LocalDateTime.now().plusMinutes(3));
//        jdbcSession.updateById(suite);
//        
//        return suite.getAccessToken();
//	}
//	
//}
